"""manabe URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.views.generic import TemplateView
from django.contrib.auth.decorators import login_required
# 这里将auth起了一个别名
from django.contrib.auth import views as auth_views
from .views import IndexView, user_login, user_register
from public.verifycode import verify_code
# from .password_views import change_token, change_email
from .password_views import change_email
from .password_views import change_password
from django.contrib.auth.views import logout_then_login
from rest_framework.authtoken import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', login_required(IndexView.as_view()), name="index"),
    path('accounts/register/', user_register, name='register'),
    path('accounts/login/', user_login, name='login'),
    path('logout/', logout_then_login, name='logout'),
    path('verify_code/', verify_code, name='verify_code'),
]

urlpatterns += [
    # login_required方法，表示此视图在用户登录之后才可以访问。如果直接在URL里访问，将会导向用户登录界面
    path('accounts/change_email/', login_required(change_email), name='change_email'),
    path('accounts/change_password/', login_required(change_password), name='change_password'),
    # PasswordResetView视图，用来生成一次性链接，发给用户注册时填写的带脑子邮件地址，让用户重设密码。
    path('reset/', auth_views.PasswordResetView.as_view(
        # 用于显示密码重设表单
        template_name='accounts/password_reset.html',
        # 用于生成带有密码重设链接的电子邮件
        email_template_name='accounts/password_reset_email.html',
        # 用于生成密码重设邮件的主题
        subject_template_name='accounts/password_reset_subject.txt'
    ),
         name='password_reset'),
    # 成功的把密码重设链接发送给用户后显示的页面
    path('reset/done/', auth_views.PasswordResetDoneView.as_view(
        template_name='accounts/password_reset_done.html'
    ),
         name='password_reset_done'),
    # 呈现输入新密码的表单
    path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(
        template_name='accounts/password_reset_confirm.html'
    ),
         name='password_reset_confirm'),
    # 呈现一个视图，告诉用户成功修改了密码
    path('reset/complete/', auth_views.PasswordResetCompleteView.as_view(
        template_name='accounts/password_reset_complete.html'
    ),
         name='password_reset_complete'),
]

urlpatterns += [
    path('api/', include('api.urls'))
]
urlpatterns += [
    path('appinput/', include('appinput.urls'))
]
urlpatterns += [
    path('deploy/', include('deploy.urls'))
]
urlpatterns += [
    path('public/', include('public.urls'))
]

urlpatterns += [
    path('rightadmin/', include('rightadmin.urls'))
]

urlpatterns += [
    path('serverinput/', include('serverinput.urls'))
]


